package com.docker.jy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.docker.chy.domain.DoctorPatient;
import com.docker.chy.mapper.DoctorPatientMapper;
import com.docker.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.jy.domain.DoctorVip;
import com.docker.jy.service.IDoctorVipService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 会员列表Controller
 * 
 * @author ruoyi
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/jy/vipList")
public class DoctorVipController extends BaseController
{
    @Autowired
    private IDoctorVipService doctorVipService;
    @Autowired
    private DoctorPatientMapper doctorPatientMapper;
    /**
     * 查询会员列表列表
     */
    @PreAuthorize("@ss.hasPermi('jy:vipList:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorVip doctorVip)
    {
        startPage();
        List<DoctorVip> list = doctorVipService.selectDoctorVipList(doctorVip);
        //遍历list
        for (DoctorVip vip : list) {
            //根据patientId查询患者信息
            DoctorPatient patient = doctorPatientMapper.selectDoctorPatientById(Long.valueOf(vip.getPatientId()));
            vip.setDoctorPatient(patient);
        }
        return getDataTable(list);
    }

    /**
     * 导出会员列表列表
     */
    @PreAuthorize("@ss.hasPermi('jy:vipList:export')")
    @Log(title = "会员列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorVip doctorVip)
    {
        List<DoctorVip> list = doctorVipService.selectDoctorVipList(doctorVip);
        ExcelUtil<DoctorVip> util = new ExcelUtil<DoctorVip>(DoctorVip.class);
        util.exportExcel(response, list, "会员列表数据");
    }

    /**
     * 获取会员列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('jy:vipList:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(doctorVipService.selectDoctorVipById(id));
    }

    /**
     * 新增会员列表
     */
    @PreAuthorize("@ss.hasPermi('jy:vipList:add')")
    @Log(title = "会员列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorVip doctorVip)
    {
        return toAjax(doctorVipService.insertDoctorVip(doctorVip));
    }

    /**
     * 修改会员列表
     */
    @PreAuthorize("@ss.hasPermi('jy:vipList:edit')")
    @Log(title = "会员列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorVip doctorVip)
    {
        return toAjax(doctorVipService.updateDoctorVip(doctorVip));
    }

    /**
     * 删除会员列表
     */
    @PreAuthorize("@ss.hasPermi('jy:vipList:remove')")
    @Log(title = "会员列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorVipService.deleteDoctorVipByIds(ids));
    }

    //根据不同会员等级查询每个等级的所有患者的总金额,然后在前端通过一个饼图展示出来
//    @Anonymous
//    @GetMapping("/selectDoctorVipByVipGrade")
//    public List<DoctorVip> selectDoctorVipByVipGrade()
//    {
//        return doctorVipService.selectDoctorVipByVipGrade();
//    }
    @Anonymous
    @GetMapping("/vipConsumptionByGrade")
    public AjaxResult getVipConsumptionByGrade() {
        List<DoctorVip> data = doctorVipService.selectVipConsumptionGroupByGrade();
        return AjaxResult.success(data);
    }
}
